﻿using Common.DictComponent;
using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class DictRepository : IDictRepository
    {
        private readonly IDbContext _dbContext;

        public DictRepository(IDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        // 方法实现与主项目一致
        public async Task<WmsDictType> GetDictTypeByCodeAsync(string code)
        {
            return await _dbContext.WmsDictType.FirstOrDefaultAsync(t => t.Code == code);
        }

        public async Task<List<WmsDictData>> GetDictDataByTypeIdAsync(long typeId)
        {
            return await _dbContext.WmsDictData.Where(d => d.DictTypeId == typeId).ToListAsync();
        }

        public async Task UpdateDictTypeAsync(WmsDictType dictType)
        {
            _dbContext.WmsDictType.Update(dictType);
            await _dbContext.SaveChangesAsync();
        }

        public async Task UpdateDictDataAsync(WmsDictData dictData)
        {
            _dbContext.WmsDictData.Update(dictData);
            await _dbContext.SaveChangesAsync();
        }
    }
}
